package manager

import (
	"gitcode.com/G-YT/ANN/server/global"
	"gitcode.com/G-YT/ANN/server/model/common/request"
	"gitcode.com/G-YT/ANN/server/model/common/response"
	"gitcode.com/G-YT/ANN/server/model/manager"
	managerReq "gitcode.com/G-YT/ANN/server/model/manager/request"
	"gitcode.com/G-YT/ANN/server/service"
	"gitcode.com/G-YT/ANN/server/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type FdHealthManagerAuditApi struct {
}

var fdHealthManagerAuditService = service.ServiceGroupApp.ManagerServiceGroup.FdHealthManagerAuditService

// CreateFdHealthManagerAudit 創建健康师注册
// @Tags FdHealthManagerAudit
// @Summary 創建健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerAudit true "創建健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"創建成功"}"
// @Router /fdHealthManagerAudit/createFdHealthManagerAudit [post]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) CreateFdHealthManagerAudit(c *gin.Context) {
	userID := utils.GetUserID(c)
	if err := fdHealthManagerAuditService.CreateFdHealthManagerAudit(userID); err != nil {
		global.GVA_LOG.Error(err.Error(), zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("創建成功", c)
	}
}

// DeleteFdHealthManagerAudit 删除健康师注册
// @Tags FdHealthManagerAudit
// @Summary 删除健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerAudit true "删除健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fdHealthManagerAudit/deleteFdHealthManagerAudit [delete]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) DeleteFdHealthManagerAudit(c *gin.Context) {
	var fdHealthManagerAudit manager.FdHealthManagerAudit
	err := c.ShouldBindJSON(&fdHealthManagerAudit)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerAuditService.DeleteFdHealthManagerAudit(fdHealthManagerAudit); err != nil {
		global.GVA_LOG.Error("删除失敗!", zap.Error(err))
		response.FailWithMessage("删除失敗", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteFdHealthManagerAuditByIds 批量删除健康师注册
// @Tags FdHealthManagerAudit
// @Summary 批量删除健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /fdHealthManagerAudit/deleteFdHealthManagerAuditByIds [delete]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) DeleteFdHealthManagerAuditByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerAuditService.DeleteFdHealthManagerAuditByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失敗!", zap.Error(err))
		response.FailWithMessage("批量删除失敗", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateFdHealthManagerAudit 更新健康师注册
// @Tags FdHealthManagerAudit
// @Summary 更新健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManagerAudit true "更新健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /fdHealthManagerAudit/updateFdHealthManagerAudit [put]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) UpdateFdHealthManagerAudit(c *gin.Context) {
	var fdHealthManagerAudit manager.FdHealthManagerAudit
	err := c.ShouldBindJSON(&fdHealthManagerAudit)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerAuditService.UpdateFdHealthManagerAudit(fdHealthManagerAudit); err != nil {
		global.GVA_LOG.Error("更新失敗!", zap.Error(err))
		response.FailWithMessage("更新失敗", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindFdHealthManagerAudit 用id査詢健康师注册
// @Tags FdHealthManagerAudit
// @Summary 用id査詢健康师注册
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManagerAudit true "用id査詢健康师注册"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"査詢成功"}"
// @Router /fdHealthManagerAudit/findFdHealthManagerAudit [get]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) FindFdHealthManagerAudit(c *gin.Context) {
	var fdHealthManagerAudit manager.FdHealthManagerAudit
	err := c.ShouldBindQuery(&fdHealthManagerAudit)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if refdHealthManagerAudit, err := fdHealthManagerAuditService.GetFdHealthManagerAudit(fdHealthManagerAudit.ID); err != nil {
		global.GVA_LOG.Error("査詢失敗!", zap.Error(err))
		response.FailWithMessage("査詢失敗", c)
	} else {
		response.OkWithData(gin.H{"refdHealthManagerAudit": refdHealthManagerAudit}, c)
	}
}

// GetFdHealthManagerAuditList 分页獲取健康师注册列表
// @Tags FdHealthManagerAudit
// @Summary 分页獲取健康师注册列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerAuditSearch true "分页獲取健康师注册列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerAudit/getFdHealthManagerAuditList [get]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) GetFdHealthManagerAuditList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerAuditSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	storeID := utils.GetUserID(c)
	pageInfo.FdHealthManager.StoreId = storeID
	if list, total, err := fdHealthManagerAuditService.GetFdHealthManagerAuditInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}

// GetScHealthManagerAuditList 獲取健康师注册列表【服务中心】
// @Tags FdHealthManagerAudit
// @Summary 獲取健康师注册列表【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerAuditSearch true "獲取健康师注册列表【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerAudit/getScHealthManagerAuditList [get]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) GetScHealthManagerAuditList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerAuditSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	ScID := utils.GetUserID(c)
	if list, total, err := fdHealthManagerAuditService.GetScHealthManagerAuditList(pageInfo, ScID); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}

// GetAllHealthManagerAuditList 分页獲取健康师注册列表
// @Tags FdHealthManagerAudit
// @Summary 分页獲取健康师注册列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerAuditSearch true "分页獲取健康师注册列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"獲取成功"}"
// @Router /fdHealthManagerAudit/getFdHealthManagerAuditList [get]
func (fdHealthManagerAuditApi *FdHealthManagerAuditApi) GetAllHealthManagerAuditList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerAuditSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	storeID := utils.GetUserID(c)
	pageInfo.FdHealthManager.StoreId = storeID
	if list, total, err := fdHealthManagerAuditService.GetFdHealthManagerAuditInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("獲取失敗!", zap.Error(err))
		response.FailWithMessage("獲取失敗", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "獲取成功", c)
	}
}
